﻿@using Kovan.Model.Entity.UserCenter;
@using Kovan.Model.ViewModel.UserCenter;
@{
    var menus = ViewBag.Menus as List<EModuleAuthority>;
    var Authoritys = ViewBag.Authoritys as List<ERoleAuthority>;
    var RoleId = ViewBag.RoleId ?? 0;
}
<style type="text/css">
ul.tree1, ul.tree1 ul { 
    list-style-type: none; 
    background: url("@Url.Content("~/content/images/vline.png")") repeat-y; 
    margin: 0; 
    padding: 0; 
} 
ul.tree1 ul { 
    margin-left: 10px; 
} 
ul.tree1 li { 
    margin: 0; 
    padding: 0 12px; 
    line-height: 20px; 
    
    background: url("@Url.Content("~/content/images/node.png")") no-repeat; 
} 
ul.tree1 li.last { 
    background: url("@Url.Content("~/content/images/lastnode.png")") no-repeat; 
}
.span_aut{
    margin-left:50px;
}
ul.tree1 label{
    float:none;
    width: auto;
    line-height: 21px;
    padding: 0px;
}
</style>
<!-- begin -->
<div id="operateAuthority" class="pageContent">
    <form method="post" action="@Url.Content("~/Manage/Role/SaveAuthority")" class="pageForm required-validate"
    onsubmit="return RoleManage.SaveAuthority(this, dialogAjaxDone);">
    <input type="hidden" name="RoleId" value="@RoleId" />
    <input type="hidden" name="authoritys" value="" />
    <div class="pageFormContent" layouth="56">
        <!—start -->
        <div style="margin-left: 20px;">
            <div>
                <a href="javascript:;">后台管理中心</a></div>
            @NodeItem(0, menus)
        </div>
        <!—end -->
    </div>
    <div class="formBar">
        <ul>
            <!--<li><a class="buttonActive" href="javascript:;"><span>保存</span></a></li>-->
            <li>
                <div class="buttonActive">
                    <div class="buttonContent">
                        <button type="submit">
                            保存</button></div>
                </div>
            </li>
            <li>
                <div class="button">
                    <div class="buttonContent">
                        <button type="button" class="close">
                            取消</button></div>
                </div>
            </li>
        </ul>
    </div>
    </form>
</div>
@helper NodeItem(long module_id, List<EModuleAuthority> list)
    {
        var Authoritys = ViewBag.Authoritys as List<ERoleAuthority>;
        var list1 = list.Where(c => c.module.parent_id == module_id);
    @Html.Raw(string.Format("<ul{0}>", module_id == 0 ? " class=\"tree1\"" : ""))
        foreach (var item in list1)
        {
            var list2 = list.Where(c => c.module.parent_id == item.module.module_id);
    @Html.Raw(string.Format("<li><label>{0}</label>",item.module.name))
    
            if (item.authoritys.Count() > 0)
            {
    <span class="span_aut">
        @foreach (var item1 in item.authoritys)
        {
            <label>
                <input type="checkbox" name="authority" value="@item1.authority_id" @(Authoritys.Count(c => c.authority_id == item1.authority_id) > 0 ? "checked" : "") />@item1.name</label>
        }
    </span>
            }
            if (list2 != null && list2.Count() > 0)
            {
    @NodeItem(item.module.module_id.Value, list)
            }
    @Html.Raw("</li>");
        }
    @Html.Raw("</ul>")
}
